<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec'
	uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
	    .asLabel .mini-textbox-border,
	    .asLabel .mini-textbox-input,
	    .asLabel .mini-buttonedit-border,
	    .asLabel .mini-buttonedit-input,
	    .asLabel .mini-textboxlist-border
	    {
	        border:0;background:none;cursor:default;
	    }
	    .asLabel .mini-buttonedit-button,
	    .asLabel .mini-textboxlist-close
	    {
	        display:none;
	    }
	    .asLabel .mini-textboxlist-item
	    {
	        padding-right:8px;
	    }    
    </style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<fieldset style="width:95%;height:30%;margin-left: 10px">
	    <legend>入库基本信息</legend>
		<form id="form1" method="post">
		<input name="id" class="mini-hidden" />
	        <div style="padding-bottom:15px;">
	            <table style="width:100%;" cellspacing="0" cellpadding="5">
	                <tr>
	                    <td style="width: 80px;">编号：</td>
	                    <td style="width:250px;"><input name="serialNum" allowInput="false" class="mini-textbox asLabel" allowInput="false" style="width: 200px;"/></td>
	                	<td style="width: 80px;">标题：</td>
	                    <td style="width:150px;"><input name="title" class="mini-textbox asLabel" allowInput="false" style="width: 200px;"/></td>
	                </tr>
	                <tr>
	                	<td>仓库：</td>
	                    <td style="width:250px;"><input name="warehouseName" class="mini-textbox asLabel" allowInput="false" style="width: 200px;"/></td>
	                    <td>类型：</td>
	                    <td style="width:150px;"><input name="typeVal" class="mini-textbox asLabel" allowInput="false" style="width: 200px;"/></td>
	                </tr>
	                <tr>
	                    <td>状态：</td>
	                    <td style="width:250px;"><input name="status" class="mini-textbox asLabel" allowInput="false" style="width: 200px;"/></td>
	                    <td>时间：</td>
	                    <td style="width:150px;"><input name="storageTime" class="mini-textbox asLabel" allowInput="false" style="width: 200px;"/></td>
	                </tr>
	                <tr>
	                    <td>填单人：</td>
	                    <td style="width:250px;"><input name="writeUserName" class="mini-textbox asLabel" allowInput="false" style="width: 200px;"/></td>
	                	<td>审核人：</td>
	                    <td style="width:150px;"><input name="auditUserName" class="mini-textbox asLabel" allowInput="false" style="width: 200px;"/></td>
	                </tr>
	            </table>
	        </div>
    	</form>
	</fieldset>
    <div style="width:97%;height:50%;margin-left: 11px;margin-top: 5px">
	    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
		    <table style="width:80%;">
		        <tr>
		            <td>
		            	<sec:authorize url='/storage_detail_add.do'>
		                <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
		                </sec:authorize>
		                <sec:authorize url='/storage_detail_edit.do'>
		                <a class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>
		                </sec:authorize>
		                <sec:authorize url='/storage_detail_del.do'>
		                <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>
		                </sec:authorize>
		                <sec:authorize url='/storage_import_view.do'>
		                <a class="mini-button" iconCls="icon-upload" onclick="openImport()">批量导入</a>
		                </sec:authorize>
		                <sec:authorize url='/storage_download.do'>
		         		<a class="mini-button" iconCls="icon-download" href="storage_download.do">下载导入模版</a>
		         		</sec:authorize>
		            </td>
		        </tr>
		    </table>           
		</div>
		<div id="datagrid1" class="mini-datagrid" style="width: 100%;height: 100%" idField="id" pageSize="20" url="storage_detail_view.do" showPager="false">
			<div property="columns" >
				<div type="indexcolumn"></div>
				<div field="medicineNo" width="100" headerAlign="center" align="center">药品编号</div>
				<div field="name" width="100" headerAlign="center" align="center">药品名称</div>
				<div field="medicineUnit" width="100" headerAlign="center" align="center">单位</div>
				<div field="quantity" width="100" headerAlign="center" align="center">入库量</div>
			</div>
		</div>
    </div>
    <div style="text-align:center;margin-top: 60px">
    	<sec:authorize url='/storage_to_audit.do'>
        <a class="mini-button" onclick="onOk" style="width:120px;">提交审核</a>
        </sec:authorize>
        <sec:authorize url='/storage_storage.do'>
        <a class="mini-button" onclick="onStorage" style="width:120px;">批准入库</a>     
        </sec:authorize>  
        <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
    </div>

<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	
	var form = new mini.Form("#form1");
	var id = mini.getbyName("id");
	var storageId = "";
    
	function add() {
	    mini.open({
	        url: "storage_detail_add.do",
	        allowResize:false,
	        title: "新增入库明细", width: 500, height: 420,
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = { action: "new", id: id.getValue()};
	            iframe.contentWindow.SetData(data);
	        },
	        ondestroy: function (action) {
	        	if(action == 'succ'){
		            grid.reload();
	        	}
	        }
	    });
	}
	
	function edit() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "storage_detail_edit.do",
                allowResize:false,
                title: "编辑入库明细", width: 500, height: 420,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", id: row.id };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                	if(action == 'succ'){
    		            grid.reload();
    	        	}
                }
            });
        } else {
            alert("请选中一条记录");
        }
    }
	
	function remove() {
        var row = grid.getSelected();
        if (row) {
            if (confirm("确定删除选中记录？")) {
                $.ajax({
                    url: "storage_detail_del.do?id=" +row.id,
                    success: function (text) {
                        grid.reload();
                    }
                });
            }
        } else {
            mini.alert("请选中一条记录");
        }
    }
	
	//标准方法接口定义
    function SetData(data) {
        if (data.action == "editDetail") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            data = mini.clone(data);
            form.setData(data.row);
            storageId = data.row.id;
        	grid.load({key: data.row.id});
            form.setChanged(false);
        }
    }
	
    function SaveData() {
    	window.CloseOwnerWindow("succ");
	}
	
    function onOk() {
		$.post("storage_to_audit.do",{id:storageId},function(data){
			if(data.success){
            	window.CloseOwnerWindow("succ");
            }else{
            	mini.alert("不能提交空的表单","警告");
            }
		},"json");
    }
    
    function onStorage() {
    	var rows = grid.getData();
    	if(rows == 0) {
    		mini.alert("不能提交空的表单","警告");
    		return;
    	}
    	var id = mini.getbyName("id");
	    $.ajax({
	        url: "storage_storage.do?id=" + id.getValue(),
			type: 'post',
			dataType: 'json',
	        cache: false,
	        success: function (text) {
	            if(text.success){
	            	window.CloseOwnerWindow("storage");
	            }else{
	            	mini.alert("数据错误！");
	            }
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	            alert(jqXHR.responseText);
	            window.CloseOwnerWindow();
	        }
	    });
	}
	
    function CloseWindow(action) {            
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
    
    function onCancel(e) {
        CloseWindow("cancel");
    }

    function openImport() {
    	mini.open({
	        url: "storage_import_view.do",
	        allowResize:false,
	        title: "导入盘点表", width: 400, height: 270,
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = {storageId:storageId};
	            iframe.contentWindow.SetData(data);
	        },
	        ondestroy: function (action) {
	        	if(action == 'succ'){
		            grid.reload();
	        	}
	        }
	    });
    }
</script>
</body>
</html>